package com.xinyue.auto.reader.process;

import java.util.List;

import org.dom4j.Element;

import com.xinyue.auto.exception.OrderException;
import com.xinyue.auto.reader.Process;
import com.xinyue.auto.reader.ProcessContext;
import com.xinyue.auto.reader.util.OrderUtil;

public class OrderProcess extends ProcessContext{
	public OrderProcess(Process read) {
		super(read);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	protected void process() throws Exception {
		Element order = xml.element(order_by_);
		
		if(order != null) {
			List<Element> os = order.elements(order_column_);
			if(os == null || os.size() == 0) {
				throw new OrderException("必须定义order-column子标签", holder.getException());
			}
			
			try {
				String orderBy = OrderUtil.validate(os, xml);
				
				//将数据封装至对象
				holder.getEntity().setOrderBy(orderBy);
			} catch (Exception e) {
				throw new OrderException(e.getMessage(), holder.getException());
			}
		}
	}
}